//创建很多子进程
#include "worker.h"
#include "head.h"
int makeChild(workerData_t *workerArr,int workerNum)
{
    pid_t pid;
    int pipeFd[2];
    
    for(int i =0;i<workerNum;i++)
    {socketpair(AF_LOCAL,SOCK_STREAM,0,pipeFd);
        pid = fork();
        if(pid ==0)
        {//子进程；
        close(pipeFd[0]);
     eventHandler(pipeFd[1]);
            
        }
        //父进程
        close(pipeFd[1]);
        printf("pipeFd = %d, pid = %d\n",pipeFd[0],pid);
        workerArr[i].pid = pid;
        workerArr[i].status = FREE;
        workerArr[i].pipeFd = pipeFd[0];
    }
}

int eventHandler(int pipeFd)
{
    while(1)
    {
  //后续的任务加到这里
   int netFd;
   recvFd(pipeFd,&netFd);
   printf("i got a task\n");
   sleep(5);
   printf("i have done task\n");
   pid_t pid = getpid();
   write(pipeFd,&pid,sizeof(pid));
   close(netFd);
    }
}